package com.wise.service.cms.content.resourcegroup;

import com.wise.entities.content.ResourceGroup;
import com.wise.entities.content.ResourceStatus;
import com.wise.framework.basic.DateTimeUtil;
import com.wise.framework.daomodel.DaoOne4Update;
import com.wise.framework.daomodel.DaoSave;
import com.wise.framework.entitiesbasic.IdTimeEntity;
import com.wise.framework.logger.Logger;
import com.wise.framework.session.CurrentUserId;
import com.wise.summer.v1.cms.content.resourcegroup.UpdateResourceGroupById;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

/**
 * @author yubo
 */
@Service
@SummerService
public class UpdateResourceGroupsService implements SummerServiceBean<UpdateResourceGroupById> {
	private static final Logger log = Logger.getLogger(UpdateResourceGroupsService.class);

	@Override
	public void sum(UpdateResourceGroupById summer) {
		ResourceGroup resourceGroups = DaoOne4Update.s(ResourceGroup.class, summer.getId(), "");
		resourceGroups.setStatus(ResourceStatus.Normal.value());
		resourceGroups.setGroupName(summer.getGroupName());
		resourceGroups.setGroupType(summer.getGroupType());
		resourceGroups.setCenter(summer.getCenter());
		setLastUpdateBy(resourceGroups);
		DaoSave.s(resourceGroups);

		summer.setSummerResult(true);
	}

	private void setLastUpdateBy(IdTimeEntity idTimeEntity) {
		String userId = CurrentUserId.s(true);
		idTimeEntity.setLastUpdateBy(userId);
		idTimeEntity.setLastUpdateDate(DateTimeUtil.timestampNow());
	}

}
